package cn.lingyangwl.agile.auth.manager;

import cn.hutool.core.collection.CollUtil;
import cn.lingyangwl.agile.auth.mapper.ExtLdpConnectMapper;
import cn.lingyangwl.agile.auth.model.entity.ExtLdpConnect;
import cn.lingyangwl.framework.tool.core.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * 身份源连接 仓储层
 *
 * @author shenguangyang
 */
@Slf4j
@Repository
public class ExtLdpConnectManager extends ServiceImpl<ExtLdpConnectMapper, ExtLdpConnect>
    implements IService<ExtLdpConnect> {

    public List<ExtLdpConnect> listByLdpId(Long ldpId) {
        if (Objects.isNull(ldpId)) {
            return Collections.emptyList();
        }
        return this.list(ExtLdpConnect.lqw().eq(ExtLdpConnect::getLdpId, ldpId));
    }

    public List<ExtLdpConnect> listByGrantTypes(List<String> grantTypes) {
        if (CollectionUtils.isEmpty(grantTypes)) {
            return Collections.emptyList();
        }
        return this.list(ExtLdpConnect.lqw().in(ExtLdpConnect::getGrantType, grantTypes));
    }

    public void deleteByLdpIds(List<Long> ldpIds) {
        if (CollUtil.isEmpty(ldpIds)) {
            return;
        }
        this.remove(ExtLdpConnect.lqw().in(ExtLdpConnect::getLdpId, ldpIds));
    }
}
